home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AOL File Library: 2,801 to 2,900
/
aol-file-protocol-4400-2801-to-2900.zip
/
AOLDLs
/
C++ Files Library
/
UVirusCheck (PP)
/
UVirusCheck.sit
/
UVirusCheck
/
UVirusCheck.cp
< prev
next >
Wrap
Text File
|
1995-08-28
|
7KB
|
214 lines
// ===========================================================================
// UVirusCheck.cp ⌐ 1995, âric Forget. All rights reserved.
// ===========================================================================
//
// ************************************************************************
// * *
// * Before using this code you should read the "License Agreement" *
// * document and agree with it. *
// * *
// ************************************************************************
//
// UVirusCheck implement a checksum (really basic one!) to the resource
// fork of an application. The first time you start your application it will
// make the checksum and write it directly in the resource fork. Each time
// later it will only read: so it is clean when sending it to customers.
//
// ---------------------------------------------------------------------------
//
// Instruction Notes:
// -----------------
//
// 1) Include the file Virus.rsrc in your project;
//
// 2) In your resource editor, copy the content of '????' ID 128 resource;
//
// 3) Create a new type (your own) and paste the content copied in it.
// Be sure that your new resource as an ID equal to 128.
//
// 4) Create an Alert (with the ID you want). It must say something like:
//
// The Application XXX is damaged or infected with a virus.
// Please install it again with originals disks.
//
// Note: The default button should be "Quit"
//
// 5) At the beginning of your application (after initialized the toolbox!),
// add the following line:
//
// StVirusCheck MyVirusCheck(MY_RES_TYPE, MY_ALERT_ID);
//
// ---------------------------------------------------------------------------
//
// Usage Notes:
// ------------
//
// You may want to comment off the line at the instruction (5) when
// debugging with the Metrowerks debugger. If you don't, each time you
// enter the debugger, it will alert you the the application version is not
// the right one. It won't tell you that for the first execution after
// a build.
//
// ---------------------------------------------------------------------------
#include "UVirusCheck.h"
#include "UEventUtils.h"
// ---------------------------------------------------------------------------
// Ñ StVirusCheck
// ---------------------------------------------------------------------------
StVirusCheck::StVirusCheck(
OSType inResType,
ResIDT inAlertID)
{
mResourceMap = ::Get1Resource(inResType, 128);
mResType = inResType;
Assert_(mResourceMap != nil);
::SetResLoad(false);
if((mResourceMap != nil) &&
(::GetHandleSize(mResourceMap) == sizeof(SResourceMapT)) &&
((**(SResourceMapT **)mResourceMap).type == 'NBRM')) {
BuildResourceMap();
} else if((mResourceMap == nil) || (!CheckIfResourceMapIsInfected())) {
::Alert(inAlertID, nil);
::ExitToShell();
}
::SetResLoad(true);
}
// ---------------------------------------------------------------------------
// Ñ ~StVirusCheck
// ---------------------------------------------------------------------------
StVirusCheck::~StVirusCheck()
{
if(mResourceMap != nil) {
::ReleaseResource(mResourceMap);
}
}
// ---------------------------------------------------------------------------
// Ñ BuildResourceMap
// ---------------------------------------------------------------------------
void
StVirusCheck::BuildResourceMap()
{
LHandleStream resourceMapStream(mResourceMap);
Int16 resourceTypeCount = ::Count1Types() - 9;
SResourceMapT resourceMap;
Handle aResource;
resourceMapStream.SetLength(sizeof(SResourceMapT) * resourceTypeCount);
resourceMapStream.SetMarker(0, streamFrom_Start);
for(Int16 i = 1; i <= resourceTypeCount; i++) {
::Get1IndType(&resourceMap.type, i);
if((resourceMap.type != mResType) &&
(resourceMap.type != 'SIZE') &&
(resourceMap.type != 'icl4') &&
(resourceMap.type != 'icl8') &&
(resourceMap.type != 'ICN#') &&
(resourceMap.type != 'ics4') &&
(resourceMap.type != 'ics8') &&
(resourceMap.type != 'ics#') &&
(resourceMap.type != 'MENU')) {
resourceMap.count = ::Count1Resources(resourceMap.type);
resourceMap.size = 0;
for(Int16 j = 1; j <= resourceMap.count; j++) {
aResource = ::Get1IndResource(resourceMap.type, j);
resourceMap.size += ::GetResourceSizeOnDisk(aResource);
}
resourceMapStream.WriteData(&resourceMap, sizeof(SResourceMapT));
}
}
resourceMapStream.DetachDataHandle();
::ChangedResource(mResourceMap);
::WriteResource(mResourceMap);
}
// ---------------------------------------------------------------------------
// Ñ CheckIfResourceMapIsInfected
// ---------------------------------------------------------------------------
Boolean
StVirusCheck::CheckIfResourceMapIsInfected()
{
Boolean outIsInfected = true;
LHandleStream resourceMapStream(mResourceMap);
Int16 resourceTypeCount = ::Count1Types() - 9;
SResourceMapT resourceMap, resourceMapActual;
Handle aResource;
if((resourceMapStream.GetLength() / sizeof(SResourceMapT)) == resourceTypeCount) {
resourceMapStream.SetMarker(0, streamFrom_Start);
for(Int16 i = 1; i <= resourceTypeCount; i++) {
::Get1IndType(&resourceMapActual.type, i);
if((resourceMapActual.type != mResType) &&
(resourceMapActual.type != 'SIZE') &&
(resourceMapActual.type != 'icl4') &&
(resourceMapActual.type != 'icl8') &&
(resourceMapActual.type != 'ICN#') &&
(resourceMapActual.type != 'ics4') &&
(resourceMapActual.type != 'ics8') &&
(resourceMapActual.type != 'ics#') &&
(resourceMapActual.type != 'MENU')) {
resourceMapActual.count = ::Count1Resources(resourceMapActual.type);
resourceMapActual.size = 0;
for(Int16 j = 1; j <= resourceMapActual.count; j++) {
aResource = ::Get1IndResource(resourceMapActual.type, j);
resourceMapActual.size += ::GetResourceSizeOnDisk(aResource);
}
resourceMapStream.ReadData(&resourceMap, sizeof(SResourceMapT));
if((resourceMapActual.type != resourceMap.type) ||
(resourceMapActual.count != resourceMap.count) ||
(resourceMapActual.size != resourceMap.size)) {
outIsInfected = false;
break;
}
}
}
} else {
outIsInfected = false;
}
resourceMapStream.DetachDataHandle();
return outIsInfected;
}